package com.itshidu.jiaowu.controller;


import com.itshidu.jiaowu.entity.User;
import com.itshidu.jiaowu.service.OutService;
import com.itshidu.jiaowu.service.UserService;
import com.itshidu.jiaowu.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XiaZengming123
 * @since 2019-07-08
 */
@Controller
public class UserAction {
    @Autowired UserService userservice;

    //登录
    @ResponseBody
    @RequestMapping("/public/login")
    public Result login(String username,String password){
        Result data= userservice.login(username, password);
        return data;
    }

    //注册
    @ResponseBody
    @RequestMapping("/public/register")
    public Object register(User user){
        Result result= userservice.register(user);
        return result;
    }


    //退出
    @ResponseBody
    @RequestMapping("/public/logout")
    public Result logout(HttpServletRequest requset){
        requset.getSession().removeAttribute("UserInfo");
        return Result.of(200);
    }


}

